package ysu.sxm.ptjc.Controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import ysu.sxm.ptjc.Domin.MonthModel;
import ysu.sxm.ptjc.Service.MonthStaticsService;
import ysu.sxm.ptjc.pojo.ProduceStatisticalInfo;

import java.util.LinkedHashMap;
import java.util.Map;

@RestController
public class MonthStaticsServlet {
    @Autowired
    MonthStaticsService monthStaticsService;
    @PostMapping(path = "/monthDefect",produces = "application/json; charset=utf-8")
    String mothStatics(@RequestBody MonthModel model){
        Map<String,Map<String, Map<String, ProduceStatisticalInfo>>> resMap=new LinkedHashMap<>();
        String res= JSON.toJSONString(resMap);
        if(model.getCarTypes()!=null&&model.getCarTypes().size()!=0){
            for (String carType : model.getCarTypes()
                 ) {
                Map<String, Map<String, ProduceStatisticalInfo>> o=new LinkedHashMap<>();
                resMap.put(carType, o);
            }
        }
        if(model.getWorkShops()!=null&&model.getWorkShops().size()!=0&&model.getCustomers()!=null&&model.getCustomers().size()!=0){
            res=monthStaticsService.monthStatistic(model,resMap);
        }
        return res;
    }
}
